<?php
$settings = variable_get ('paypal_settings', array ());

// Encrypte
$form['private_key'] = array (
  '#type' => 'textfield',
  '#title' => 'Private key file path',
  '#default_value' => $settings['private_key'],
  '#size' => 35
);

$form['public_certificate'] = array (
  '#type' => 'textfield',
  '#title' => 'Public certificate file path',
  '#default_value' => $settings['public_certificate'],
  '#size' => 35
);

$form['paypal_certificate'] = array (
  '#type' => 'textfield',
  '#title' => 'Paypal\'s public certificate file path',
  '#default_value' => $settings['paypal_certificate'],
  '#size' => 35
);

$form['certificate_id'] = array (
  '#type' => 'textfield',
  '#title' => 'Paypal\'s public certificate ID',
  '#description' => 'Your public certificate ID given by Paypal.',
  '#default_value' => $settings['certificate_id'],
  '#size' => 35
);

$form['pdt_token'] = array (
  '#type' => 'textfield',
  '#title' => 'PDT token',
  '#default_value' => $settings['pdt_token'],
  '#size' => 35
);
// ! Encrypte

$form['image'] = array (
  '#type' => 'textfield',
  '#title' => 'Site logo',
  '#default_value' => $settings['image'],
  '#description' => 'Logo image to be display on Paypal payment pages. It should be started with http<strong><u>s</u></strong>://',
  '#size' => 35
);

$form['receiver_email'] =  array(
  '#type' => 'textfield',
  '#title' => t('PayPal Receiver Email'),
  '#default_value' => $settings['receiver_email'] ? $settings['receiver_email'] : variable_get("site_mail", ini_get("sendmail_from")),
  '#maxlength' => 180, 
  '#description' => t('Primary email address of the payment recipent. This is also your main paypal email address.'),
  '#size' => 35
);

$form['url'] =  array(
  '#type' => 'textfield', 
  '#title' => t('PayPal processing URL'),
  '#default_value' => $settings['url'] ? $settings['url'] : 'https://www.paypal.com/xclick/',
  '#size' => 35, 
  '#maxlength' => 180, 
  '#description' => t('URL of the secure payment page customers are sent to for payment processing.')
);

$form['return_url'] =  array(
  '#type' => 'textfield', 
  '#title' => t('Successful payment URL'), 
  '#default_value' => $settings['return_url'] ? $settings['return_url'] : '%order-history',
  '#size' => 35, 
  '#maxlength' => 180,
  '#description' => t("This is the destination to which you would like to send your customers when their payment has been successfully completed. The URL must be a Drupal system path. If you are not using clean URLs, specify the part after '?q='. If unsure, specify 'node'. You may also enter '%order-history' to link to the user's order history.")
);

$form['cancel_url'] =  array(
  '#type' => 'textfield',
  '#title' => t('Cancel payment URL'),
  '#default_value' => $settings['cancel_url'] ? $settings['cancel_url'] : 'node',
  '#size' => 35,
  '#maxlength' => 180,
  '#description' => t("This is the destination to which you would like to send your customers if they cancel their payment. The URL must be a Drupal system path. If you are not using clean URLs, specify the part after '?q='. If unsure, specify 'node'.")
);

$form['ipnrb_url'] = array(
  '#type' => 'textfield',
  '#title' => t('PayPal IPN "request back" validation URL'),
  '#default_value' => $settings['ipnrb_url'] ? $settings['ipnrb_url'] : 'http://www.paypal.com/cgi-bin/webscr',
  '#size' => 35,
  '#maxlength' => 180,
  '#description' => t('URL where IPN "request back" is posted to validate the transaction.'),
);  

$currency_codes = array(
  'USD' => 'USD - U.S. Dollars',
  'EUR' => 'EUR - Euros',
  'AUD' => 'AUD - Australian Dollars',
  'CAD' => 'CAD - Canadian Dollars',
  'GBP' => 'GBP - Pounds Sterling',
  'JPY' => 'JPY - Yen',
  'NZD' => 'NZD - New Zealand Dollar',
  'CHF' => 'CHF - Swiss Franc',
  'HKD' => 'HKD - Hong Kong Dollar',
  'SGD' => 'SGD - Singapore Dollar',
  'SEK' => 'SEK - Swedish Krona',
  'DKK' => 'DDK - Danish Krone',
  'PLN' => 'PLN - Polish Zloty',
  'NOK' => 'NOK - Norwegian Krone',
  'HUF' => 'HUF - Hungarian Forint',
  'CZK' => 'CZK - Czech Koruna'
);

$form['currency_code'] =  array(
  '#type' => 'select',
  '#title' => t('Currency code'),
  '#default_value' => $settings['currency_code'] ? $settings['currency_code'] : 'USD',
  '#options' => $currency_codes,
  '#description' => t('The currecy code that PayPal should process the payment in.')
);

$form['debug'] =  array (
  '#type' => 'radios',
  '#title' => t('Debug Instant Payment Notification (IPN)'), 
  '#default_value' => $settings['debug'] ? $settings['debug'] : 0,
  '#options' => array(t('Disabled'), t('Enabled')),
  '#description' => t('If enabled, you\'ll receive an email whenever IPN is activated on your site.')
);

$form['min_amount'] =  array(
  '#type' => 'textfield',
  '#title' => t('Minimum purchase amount'),
  '#default_value' => $settings['min_amount'] ? $settings['min_amount'] : '5.00',
  '#field_prefix' => '$',
  '#size' => 10,
  '#maxlength' => 10, 
  '#description' => t('What is the minimum amount an user must purchase for when checking out with Paypal?')
);

// Cấu hình người dùng loại nào có quyền thực hiện sale payment
$roles = user_roles ();
// var_dump ($roles);$tmp = array();foreach ($roles as $key => $val) {  $tmp['role_' . $key] = $val;}
$roles = $tmp;

$form['roles'] = array (  '#type' => 'checkboxes',  '#title' => 'Roles',  '#description' => 'Which role can make payment without pending',  '#default_value' => $settings['roles'] ? $settings['roles'] : array (),  '#options' => $roles);

$form['submit'] = array (
  '#type' => 'submit',
  '#value' => t('Submit')
);

